const { DataTypes } = require('sequelize');
let sequelize = require("../db");

const Clazz = require("./Clazz");

const model = sequelize.define('Student', {
  id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    primaryKey: true,
    autoIncrement: true
  },
  name: {
    type: DataTypes.STRING,
    allowNull: false,
    primaryKey: false
  },
  class_id: {
    type: DataTypes.INTEGER,
    allowNull: true,
    primaryKey: false
  },

}, {
  sequelize,
  timestamps: false,
  tableName: 't_student',
});

Student.belongsTo(Clazz, {
  foreignKey: 'class_id',
  sourceKey: "id",
  as: "class_info"
})

module.exports = model